Skip to content

fix: correct -e false negative for stat results with mode 0#83

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-e-mode-zero-false-negative
Draft

fix: correct -e false negative for stat results with mode 0#83
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-e-mode-zero-false-negative

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

What

Fix -e returning false for mocked files whose stat has mode 0.

Why

The -e handler in _check_from_stat tested scalar @stat && $stat[ST_MODE].
Since mode 0 is falsy in Perl, any file mocked with all-zero stat fields
(or just mode 0) would incorrectly report as non-existent. In Unix semantics,
stat() success alone implies existence — mode is irrelevant for that check.

Also fixes a gap in the XS stat array size validation where a 1-element array
(AvFILL == 0) slipped through the > 0 guard undetected.

How

  • Changed -e handler to _to_bool(scalar @stat) — existence depends only on stat success
  • Changed XS validation from av_size > 0 to av_size >= 0 with improved error message
  • Updated test expectation: [(0) x 13] means "file exists with all-zero fields"

Testing

Full test suite passes (make test).

🤖 Generated with Claude Code

@atoomic
Copy link
Copy Markdown
Contributor

atoomic commented Apr 18, 2026

@Koan-Bot rebase

The -e handler in _check_from_stat checked $stat[ST_MODE] in addition
to @stat array length for existence. A file with mode 0 (all permission
bits clear) would incorrectly report as non-existent, since mode 0 is
falsy in Perl. In Unix semantics, stat() success alone implies existence
regardless of mode value.

Also tighten the XS-level stat array size validation: arrays with exactly
1 element slipped through the > 0 check (AvFILL returns 0 for 1-element
arrays). Changed to >= 0 to reject all invalid sizes except -1 (empty)
and 12 (13 elements).
@Koan-Bot
Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan.atoomic/fix-e-mode-zero-false-negative was rebased onto main and review feedback was applied.

Stats

3 files changed, 5 insertions(+), 5 deletions(-)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=The -e handler on main still tests $stat[ST_MODE] which is falsy for mode 0, and the XS guard still )
  • Resolved merge conflicts (1 round(s))
  • Rebased koan.atoomic/fix-e-mode-zero-false-negative onto upstream/main
  • Pre-push CI check: previous run passed
  • Force-pushed koan.atoomic/fix-e-mode-zero-false-negative to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@Koan-Bot Koan-Bot force-pushed the koan.atoomic/fix-e-mode-zero-false-negative branch from 65344af to 2215d69 Compare April 18, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants